package com.hyron.server.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class StringComparator implements Comparator<String>
{
	public static void main(String[] args)
	{
		ArrayList<String> array = new ArrayList<String>();
		array.add("3");
		array.add("1");
		array.add("2");
		Collections.sort(array, new StringComparator(StringComparator.DESC));
		for (String str : array)
		{
			System.out.println(str);
		}
		
		System.out.println();
		
		String all[] = { "2", "3", "1" };
		Arrays.sort(all, new StringComparator(StringComparator.ASC));
		for (String str : all)
		{
			System.out.println(str);
		}
	}

	public final static int ASC = 1;
	public final static int DESC = -1;

	private int NOA = 1;
	private int NOB = -1;

	public StringComparator()
	{
	}

	public StringComparator(int order)
	{
		if (StringComparator.DESC == order)
		{
			NOA = -1;
			NOB = 1;
		}
	}

	public int compare(String o1, String o2)
	{
		if (o1.compareTo(o2) > 0)
		{
			return NOA;
		} else if (o1.compareTo(o2) < 0)
		{
			return NOB;
		} else
		{
			return 0;
		}
	}
}

